//
//  YMRentFreeCell.swift
//  RentFreeDemo
//
//  Created by youmy on 2018/11/23.
//  Copyright © 2018 youmy. All rights reserved.
//

import UIKit

class YMRentFreeCell: UITableViewCell {
    
    var textLb: UILabel!
    var detailTextLb: UILabel!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        
        textLb = UILabel()
        detailTextLb = UILabel()
        
        textLb?.font = UIFont(name: PingFangSC_Regular, size: 14)
        textLb.lineBreakMode = .byTruncatingTail
        detailTextLb?.font = UIFont(name: PingFangSC_Regular, size: 14)
        textLb?.textColor = UIColor(valueRGB: 0x242424, alpha: 1)
        detailTextLb?.textColor = UIColor(valueRGB: 0x242424, alpha: 1)
        detailTextLb?.textAlignment = .right
        
        contentView.addSubview(textLb)
        contentView.addSubview(detailTextLb)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        detailTextLb.sizeToFit()
        
        let space:CGFloat = 20
        let height:CGFloat = 14
        textLb.frame = CGRect(x: space, y: 0, width: 240, height: height)
        detailTextLb.frame = CGRect(x: width - detailTextLb.width - 20, y: 0, width: detailTextLb.width, height: height)
        textLb.centerY = contentView.centerY
        detailTextLb.centerY = contentView.centerY
    }
    
    func config(_ model:YMRentFreeModel?){
        
        guard let obj = model else {
            return
        }
        
        textLb?.text = obj.title
        detailTextLb?.text = obj.price
    }
}
